#include <iostream>

using namespace std;

const int N = 110;

char f[N][N];

int n, m;

int main()
{
	cin >> n >> m;
	
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= m; j ++ )
			cin >> f[i][j];
			
	for (int i = 1; i <= n; i ++ )
		for (int j = 2; j <= m; j ++ )
			if (f[i][j - 1] != f[i][j])
			{
				puts("NO");
				return 0;
			}
			
//			exit(0);
			
	for (int i = 2; i <= n; i ++ )
		if (f[i][1] == f[i - 1][1]) 
		{
			puts("NO");
			return 0;
		}
		
	puts("YES");
	return 0;
		
	
}